<!DOCTYpE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head th:replace="admin/_fragments :: head(~{::title})">
		<title>博客管理</title>
	</head>
	<body>
		<!--导航-->
		<nav th:replace="admin/_fragments :: menu(1)"></nav>
		<div class="ui attached pointing menu">
			<div class="ui container">
				<div class="right menu">
					<a th:href="@{/admin/blogs/input}" class="item">发布</a>
					<a th:href="@{/admin/blogs}" class="teal active item">列表</a>
				</div>
				
			</div>
			
		</div>
		
		
		<!--中间内容-->
		<div class="m-container-small m-padded-tb-big">
			<div class="ui container">
				<div class="ui secondary segment form">
					<input type="hidden" name="page">
					<div class="inline fields">
						<div class="field">
							<input type="text" name="title" placeholder="标题" />
						</div>
						<div class="field">
							<div class="ui labeled action input">
								<div class="ui type selection dropdown">
									<input type="hidden" name="typeId" />
									<i class="dropdown icon"></i>
									<div class="default text">分类</div>
									<div class="menu">
										<div th:each="type : ${types}" class="item" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
									</div>
								</div>
								<button class="ui compact button " id="clear_btn">clear</button>
							</div>

						</div>
						<div class="field m-padded-tb">
							<div class="ui checkbox">
								<input type="checkbox" name="recommend" />
								<label for="recommend">推荐</label>
							</div>
						</div>
						<div class="field">
							<button type="button" id="search_btn" class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
						</div>
						
					</div>
					
						
				</div>
				<div id="table-container">
					<table class="ui compact teal table" th:fragment="blogList">
						<thead>
						<tr>
							<th></th>
							<th>标题</th>
							<th>类型</th>
							<th>推荐</th>
							<th>状态</th>
							<th>更新时间</th>
							<th>操作	</th>
						</tr>
						</thead>
						<tbody>
						<tr th:each="blog,iterStat : ${page.content}">
							<td  th:text="${iterStat.count}"></td>
							<td  th:text="${blog.title}"></td>
							<td  th:text="${blog.type.name}"></td>
							<td th:text="${blog.recommend} ? '是':'否'"></td>
							<td th:text="${blog.published} ? '发布':'草稿'"></td>
							<td th:text="${blog.updateTime}"></td>
							<td>
								<a class="ui mini teal button " th:href="@{/admin/blogs/{id}/input(id=${blog.id})}">编辑</a>
								<a class="ui mini red button " th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}">删除</a>
							</td>
						</tr>
						</tbody>
						<tfoot>
						<tr>
							<th colspan="7">
								<div class="ui mini pagination menu" th:if="${page.totalPages}>1">
									<a onclick="page(this)" th:attr="data-page=${page.number}-1" class="item " th:unless="${page.first}">上一页</a>
									<a onclick="page(this)" th:attr="data-page=${page.number}+1" class="item" th:unless="${page.last}">下一页</a>
								</div>
								<a th:href="@{/admin/blogs/input}" class="ui mini right floated primary button">新增</a>

							</th>
						</tr>
						</tfoot>
					</table>
					<div class="ui success message" th:unless="${#strings.isEmpty(msg)}">
						<i class="close icon"></i>
						<div class="header">提示：</div>
						<p th:text="${msg}"></p>
					</div>
				</div>

			
			
			
			
			
			
			</div>
		</div>
		<br/>
		<br/>
		<br/>
		<!--底部-->
		<footer th:replace="admin/_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive"></footer>
		<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
		<script>
			//移动端下点击才可以显示目录
			$('.menu.toggle').click(function(){
				$('.m-item').toggleClass('m-mobile-hide');
			});
			//注销
			$('.ui.dropdown').dropdown({
				on: 'hover'
			});
			//分页显示
			function page(obj) {
				$("[name='page']").val($(obj).data("page"));
				loaddata();
			};

			//消息提示关闭初始化
			$('.message .close').on('click',function () {
				$(this)
						.closest('.message')
						.transition('fade');
			});
			//清除分类搜索条件
			$('#clear_btn').on('click', function () {
				$('.ui.type.dropdown').dropdown('clear');
			});

			//搜索按钮
			$("#search_btn").click(function () {
				$("[name='page']").val(0);
				loaddata();
			});
			//利用ajax去做搜索功能
			function loaddata() {
				$("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
					title : $("[name='title']").val(),
					typeId : $("[name='typeId']").val(),
					recommend : $("[name='recommend']").prop('checked'),
					page : $("[name='page']").val()
				});
			}


		</script>
	</body>
</html>
